package
{
	import core.Global;
	
	import events.Msg_FileDownload;
	import events.Msg_FileDownloading;
	import events.Msg_GamePause;
	import events.Msg_GetVersionInfo;
	import events.Msg_LoadingInit;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.text.TextField;
	
	import games.flvPlayer.Player;
	import games.isoMatric.IsoMatricGame;
	import games.ninJumpDx.NinJump;
	
	import interfaces.IGame;
	import interfaces.ILoading;
	import interfaces.IMsgListener;
	
	import ui.loading.LoadingContainer;
	import ui.loading.McLoading;
	import ui.loading.TextLoading;
	
	public class GFrame extends Sprite implements IMsgListener
	{
		private static var MSG_TABLE:Array = [
			Msg_GetVersionInfo.M_GETVERSIONINFO,
			Msg_LoadingInit.M_LOADINIT,
			Msg_FileDownload.M_FILEDOWNLOAD,
			Msg_GamePause.M_GAMEPAUSE,
		];
		private static var LOADING_URL:String = "ui/loading.swf";
		//public static var MAIN_UI:String = "ui/NinJumpDeluxeHD.swf";
		public static var MAIN_UI:String = "isoMatric/public.swf";
		//private static var MAIN_UI:String = "flvPlayer/ui/player_skin.swf";
		
		private var m_loadingUI:Sprite;	// 进度UI容器
		private var m_game:IGame;
		
		public function GFrame()
		{
			addEventListener(Event.ADDED_TO_STAGE,init);
		}
		
		public function msgManager(e:* = null):void
		{
			switch( e.data.msgid)
			{
				case Msg_GetVersionInfo.M_GETVERSIONINFO:
					onGetVersion(e.data);
					break;
				case Msg_LoadingInit.M_LOADINIT:
					onInitLoading(e.data);
					break;
				case Msg_FileDownload.M_FILEDOWNLOAD:
					onFileDownload(e.data);
					break;
			}
		}
		
		private function init(e:Event = null):void
		{
			stage.frameRate = 60;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			// 初始化游戏
			Global.init(this.stage);
			initListener();
		}
		
		private function initUI():void
		{
			// 初始化loading 动画
			m_loadingUI = new LoadingContainer();
			addChild(m_loadingUI);
		}	
		
		private function initListener():void
		{
			Global.addListeners(MSG_TABLE,this);
			addEventListener(Event.ENTER_FRAME,onGameEnter);
		}
		
		private function onGameEnter(e:Event):void
		{
			Global.updateAction();
		}
		
		//---------------------------------------------------------------------------------
		private function onGetVersion(e:Msg_GetVersionInfo):void
		{
			trace("get ver...");
			initUI();
		}
		
		private function onInitLoading(e:Msg_LoadingInit):void
		{
			trace("init loading...");
			Global.loadSwf(MAIN_UI);
		}
		
		private function onFileDownload(e:Msg_FileDownload):void
		{
			if(e.url == MAIN_UI)
			{
				trace("loaded ui....");
				//m_game = new NinJump();
				//m_game = new Player();
				m_game = new IsoMatricGame();
				m_game.start();
			}
			
		}
		
	}
}